//
//  CellOfCellOfMostPopularCommendScenicSpotView.m
//  FreeTravel
//
//  Created by 徐康 on 16/9/5.
//  Copyright © 2016年 KX. All rights reserved.
#import "FreeTravelMacro.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
#import "CellOfCellOfMostPopularCommendScenicSpotView.h"
@interface CellOfCellOfMostPopularCommendScenicSpotView ()
@property (nonatomic, strong) UIImageView *imageViewOfPhoto;
@property (nonatomic, strong) UIImageView *firstStar;
@property (nonatomic, strong) UIImageView *secondStar;
@property (nonatomic, strong) UIImageView *thirdStar;
@property (nonatomic, strong) UIImageView *forthStar;
@property (nonatomic, strong) UIImageView *fifthStar;
@property (nonatomic, strong) UILabel *labelOfName;
@property (nonatomic, strong) UILabel *labelOfScore;
@end
@implementation CellOfCellOfMostPopularCommendScenicSpotView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.imageViewOfPhoto = [[UIImageView alloc]init];
        self.firstStar = [[UIImageView alloc]init];
        self.secondStar = [[UIImageView alloc]init];
        self.thirdStar = [[UIImageView alloc]init];
        self.forthStar = [[UIImageView alloc]init];
        self.fifthStar = [[UIImageView alloc]init];
        self.labelOfName = [[UILabel alloc]init];
        self.labelOfScore = [[UILabel alloc]init];
        [self.contentView addSubview:self.imageViewOfPhoto];
        [self.contentView addSubview:self.firstStar];
        [self.contentView addSubview:self.secondStar];
        
        [self.contentView addSubview:self.thirdStar];
        [self.contentView addSubview:self.forthStar];
        [self.contentView addSubview:self.fifthStar];
        [self.contentView addSubview:self.labelOfScore];
        [self.contentView addSubview:self.labelOfName];
        
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    [self.imageViewOfPhoto mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.contentView);
        
        make.height.mas_equalTo(self.imageViewOfPhoto.mas_width);
    }];
    [self.labelOfName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left);
        make.right.equalTo(self.contentView.mas_right);
        make.top.equalTo(self.imageViewOfPhoto.mas_bottom).mas_offset(5);
        make.height.mas_offset(10);
    }];
    self.labelOfName.font = [UIFont systemFontOfSize:14];
    [self.labelOfScore mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.firstStar);
        make.height.equalTo(self.firstStar);
        make.right.equalTo(self.contentView.mas_right);
    }];
    self.labelOfScore.font = [UIFont systemFontOfSize:14];
    [self.firstStar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left);
        make.top.equalTo(self.labelOfName.mas_bottom).mas_offset(5);
        make.width.equalTo(self.contentView).multipliedBy(0.111);
        make.bottom.equalTo(self.contentView);
        
    }];
    
    [self.secondStar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.firstStar.mas_right);
        make.centerY.equalTo(self.firstStar);
        make.height.equalTo(self.firstStar);
        make.width.equalTo(self.firstStar);
    }];
    [self.thirdStar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.secondStar.mas_right);
        make.centerY.equalTo(self.firstStar);
        make.height.equalTo(self.firstStar);
        make.width.equalTo(self.firstStar);
    }];
    [self.forthStar mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.thirdStar.mas_right);
        make.centerY.equalTo(self.firstStar);
        make.height.equalTo(self.firstStar);
        make.width.equalTo(self.firstStar);
    }];
    [self.fifthStar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.forthStar.mas_right);
        make.centerY.equalTo(self.firstStar);
        make.height.equalTo(self.firstStar);
        make.width.equalTo(self.firstStar);
    }];
}
- (void)setModel:(ModelOfMostPopularCommendScenicSpotView *)model{
    _model = model;
    self.labelOfName.text = model.name;
    self.labelOfScore.text = model.score;
    [self.imageViewOfPhoto sd_setImageWithURL:[NSURL URLWithString:model.photo]];
    
    if (self.labelOfScore.text.integerValue < 1) {
        self.firstStar.image = [UIImage imageNamed:@"app_star_empty"];
    }else{
        if (self.labelOfScore.text.integerValue >= 1 && self.labelOfScore.text.integerValue < 2) {
            self.firstStar.image = [UIImage imageNamed:@"app_star_half"];
        }else{
            self.firstStar.image = [UIImage imageNamed:@"app_star_full"];
            if (self.labelOfScore.text.integerValue >= 2 && self.labelOfScore.text.integerValue < 3) {
                self.secondStar.image = [UIImage imageNamed:@"app_star_empty"];
            }else{
                if (self.labelOfScore.text.integerValue >= 3 && self.labelOfScore.text.integerValue < 4) {
                    self.secondStar.image = [UIImage imageNamed:@"app_star_half"];
                }else{
                    self.secondStar.image = [UIImage imageNamed:@"app_star_full"];
                    if (self.labelOfScore.text.integerValue >= 4 && self.labelOfScore.text.integerValue < 5) {
                        self.thirdStar.image = [UIImage imageNamed:@"app_star_empty"];
                    }else{
                        if (self.labelOfScore.text.integerValue >= 5 && self.labelOfScore.text.integerValue < 6) {
                            self.thirdStar.image = [UIImage imageNamed:@"app_star_half"];
                        }else{
                            self.thirdStar.image = [UIImage imageNamed:@"app_star_full"];
                            if (self.labelOfScore.text.integerValue >= 6 && self.labelOfScore.text.integerValue < 7) {
                                self.forthStar.image = [UIImage imageNamed:@"app_star_empty"];
                            }else{
                                if (self.labelOfScore.text.integerValue >= 7 && self.labelOfScore.text.integerValue < 8) {
                                    self.forthStar.image = [UIImage imageNamed:@"app_star_half"];
                                }else{
                                    self.forthStar.image = [UIImage imageNamed:@"app_star_full"];
                                    if (self.labelOfScore.text.integerValue >= 8 && self.labelOfScore.text.integerValue < 9) {
                                        self.fifthStar.image = [UIImage imageNamed:@"app_star_empty"];
                                    }else{
                                        if (self.labelOfScore.text.integerValue == 10) {
                                            self.fifthStar.image = [UIImage imageNamed:@"app_star_full"];
                                        }else{
                                            self.fifthStar.image = [UIImage imageNamed:@"app_star_half"];
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    
    
    
}
@end
